<?php
namespace app\admin\validate;

/**
* 验证器
*/
use think\Validate;
class AuthRule extends Validate
{
	protected $rule =   [
        'title'         =>  'require|max:25|unique:auth_rule',
        'pid'           =>  'number',
        'name'			=>	'require|max:50|unique:auth_rule'
    ];
    
    protected $message  =   [
        'title.require' => '名称必须',
        'title.max'     => '名称最多不能超过25个字符',
        'title.unique'  => '名称已经存在',        

        'pid.number'    => '上级栏目参数错误',
        'pid.checkpid'    => '上级栏目不能为自身',

        'name.require' => '地址必须',
        'name.max'     => '地址最多不能超过25个字符',
        'name.unique'  => '地址已经存在',       
    ];


    /* 止写法已经不支持了
    protected $scene = [
        'edit'  =>  [
            'title'     =>  'require|max:25|unique:arctype',
            'pid'       =>  'number|checkpid:pid',
        ],
    ];

    protected $scene = [
        'edit'  =>  ['title'=>'require|max:25|unique:arctype'],
    ];

*/
    // edit 验证场景定义
    public function sceneedit()
    {
        return $this->only(['title','pid','name']);
            //->append('title', 'unique:auth_rule,title^id')
            //->append('name', 'unique:auth_rule,name^id');

    }  






/*
    // edit 验证场景定义  
    public function sceneedit()
    {
        return $this->only(['username','password','grade'])
            ->remove('password', 'require');
    }  
    */
/*
    // 自定义验证规则
    protected function checkName($value,$rule,$data=[])
    {
    	if(empty($data['id'])){
    		$where = ['username'=>$value]; //新增加时
    	}else{
    		$where = ['username'=>$value,'id'=>['neq',$data['id']]];  //修改时
    	}
    	$typename = model('user')->where($where)->select();
        if(empty($typename)) {
           return true;
        }else{
        	return false;
        }
    }
*/	
}